package com.hy.admin.controller.pages;

import com.hy.admin.helper.response.NewsResponse;
import com.hy.admin.service.NewsService;
import com.hy.core.response.ServicesResult;
import org.apache.commons.httpclient.HttpStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;


/**
 * Created by yangqq on 18/4/3.
 * 个人中心
 */
@Controller
@RequestMapping("/page/share")
public class PageControllerShare extends PageControllerBase{

    @Autowired
    private NewsService newsService;

    @RequestMapping(value={"introduce" }, method=RequestMethod.GET)
    public String introduce(Model model) {

        saveDefaultAttributes2Model(model);

        return makeViewName("introduce");
    }

    @RequestMapping(value={"teacher" }, method=RequestMethod.GET)
    public String teacher(Model model) {
        saveDefaultAttributes2Model(model);
        return makeViewName("teacher");
    }

    @RequestMapping(value={"news" }, method=RequestMethod.GET)
    public String news(Model model, Long id) {
        saveDefaultAttributes2Model(model);
        ServicesResult<NewsResponse> servicesResult = newsService.detail(id);
        if(servicesResult.getStatusCode() == HttpStatus.SC_OK && servicesResult.getResult() != null) {
            model.addAttribute("news", servicesResult.getResult().getNews());
            model.addAttribute("imgList", servicesResult.getResult().getImgList());
        }
        return makeViewName("news");
    }

    @Override
    protected String getViewPrefix() {
        return "share/";
    }
}
